﻿guestBookApp.controller('recordFormController',
    ["$scope", "$modalInstance", "DataService",
    function recordFormController($scope, $modalInstance, DataService) {

        $scope.record = {};

        $scope.isInvalid = function () {
            $scope.recordForm.userName.$invalid
        }


        $scope.cancelForm = function () {
            $modalInstance.dismiss();
        };

        $scope.submitForm = function () {
            DataService.addNewRecord($scope.record).then(
                  function (results) {
                      // on success
                      $scope.record = results.data;
                      $modalInstance.close($scope.record);
                  },
                  function (results) {
                      // on error
                      $scope.hasFormError = true;
                      $scope.modelState = results.data.modelState;
                  });
        };
    }]);